/* idbLib.h - main header file for IDB+ */
/* Copyright 2003-2005 Neotune Information Technology Co., Ltd. */
/*
* DESCRIPTION:
*   idbLib.h contains the definitions for constants, data structures,
*   enumerations and function prototypes used to implement IDB+.
*/

#ifndef __INCidbLibh
#define __INCidbLibh

#ifdef __cplusplus
extern "C" {
#endif

/******************************************************************************
* SNMP/IDB+ Definitions (to help understand the IDB+ structures):
*
* object identifier: An object identifier (OID) is a sequence of non-negative
*     numbers that represent a MIB object in a MIB tree.  Each number in an
*     OID is referred to as a sub-identifier.  There can be a maximum of 128
*     sub-identifiers in an OID and each sub-identifier can have a maximum
*     value of 2^32 - 1 (or 4294967295).
*
* OID prefix: The OID prefix is the OID value without any index information
*     and identifies the object class.  The OID prefix for the RFC1213
*     sysDescr MIB object is "1.3.6.1.2.1.1.1".
*
* OID suffix: The OID suffix is the index information that identifies the
*     specific instance within an object class.  The OID suffix for a scalar
*     object is always '0'.  For a table that is indexed by an IP address
*     with a value of "192.1.192.155", the OID suffix is "192.1.192.155"
*     (i.e., has 4 sub-identifiers).
*
* sub-identifiers: Each number in an OID is referred to as a sub-identifier.
*     IDB+ stores each sub-identifier in a ulong_t (e.g., in a ulong_t
*     array element).
*
* IDB+ Object Tag: An IDB+ object tag consists of the concatenation of the
*     IDB+ Module name, ':', and the IDB+ object name.  The IDB+ Object Tag
*     string for the RFC1213 sysDescr object is "rfc1213:sysDescr".  The 
*     IDB+ 'objName' and 'altObjName' both use the IDB+ object tag format.
*/
 
#include "windows.h"
#include "neos_vx_win.h"


/******************************************************************************
* ERRNO values.
*/
#define S_idbLib_TOOBIG           (M_idbLib | 1)
#define S_idbLib_GENERROR         (M_idbLib | 2)
#define S_idbLib_NULL_BUFFER      (M_idbLib | 3)
#define S_idbLib_INDEX_RANGE      (M_idbLib | 4)
#define S_idbLib_BAD_MAGIC        (M_idbLib | 5)
#define S_idbLib_AltObject        (M_idbLib | 6)
#define S_idbLib_ObjectHidden     (M_idbLib | 7)
#define S_idbLib_INVALID_RANGE    (M_idbLib | 8)
#define S_idbLib_INVALID_LENGTH   (M_idbLib | 9)

/*
 * New errors/exceptions for compatiblity with SNMPv2/v3.
 * Except for NOSUCHINSTANCE, NONEXTINSTANCE and ENDOFMIBVIEW, all of the
 * following errors are relevant during IDB_VALIDATE phase only. The
 * exceptions occur during IDB_GET or IDB_GET_NEXT requests.
 */
#define S_idbLib_NOSUCHINSTANCE   (M_idbLib | 10)
#define S_idbLib_NOSUCHOBJECT     (M_idbLib | 11)
#define S_idbLib_NONEXTINSTANCE   (M_idbLib | 12)

#define S_idbLib_NO_CREATION      (M_idbLib | 13)
#define S_idbLib_INCONSIST_VALUE  (M_idbLib | 14)
#define S_idbLib_INCONSIST_NAME   (M_idbLib | 15)
#define S_idbLib_RESOURCE_UNAVAIL (M_idbLib | 16)
#define S_idbLib_COMMIT_FAILED    (M_idbLib | 17)
#define S_idbLib_UNDO_FAILED      (M_idbLib | 18)
#define S_idbLib_AUTHORIZATION    (M_idbLib | 19)
#define S_idbLib_NOT_WRITABLE     (M_idbLib | 20)
#define S_idbLib_NO_ACCESS        (M_idbLib | 21)
#define S_idbLib_WRONGTYPE        (M_idbLib | 22)
#define S_idbLib_WRONGVALUE       (M_idbLib | 23)
#define S_idbLib_WRONGLENGTH      (M_idbLib | 24)
#define S_idbLib_ENDOFMIBVIEW     (M_idbLib | 25)
#define S_idbLib_WRONGENCODING    (M_idbLib | 26)

#define S_idbLib_GROUP_INDEX      (M_idbLib | 30)
#define S_idbLib_GROUP_ALLOC      (M_idbLib | 31)

/******************************************************************************
* idbRequest_t - IDB+ request type enumerations
*/
typedef enum
{
    IDB_GET_NEXT    = 1,
    IDB_GET         = 2,
#define IDB_SET (IDB_GET + 1)
                /*
                 * Note: IDB_SET is not in this list since it causes
                 * the compiler to issue warnings since the switch
                 * statements want all enums to be present.
                 */
#define IDB_FORCE_MSK 0x80
#define IDB_FORCE_SET (IDB_SET | IDB_FORCE_MSK)
    IDB_SET_NVM     = 4,
    IDB_VALIDATE    = 5,        /* internal request to IDB+ Modules */
    IDB_COMMIT      = 6         /* internal request to IDB+ Modules */
} idbRequest_t;

/******************************************************************************
* idbAccess_t - IDB+ permission definition bit fields
*
* Note that some values can be OR'ed together (e.g., for read-create, use
* "IDB_READ | IDB_CREATE").
*/
typedef enum
{
    IDB_NONE            = 0x00,
    IDB_READ            = 0x01,
    IDB_WRITE           = 0x02,
    IDB_CREATE          = 0x04,
    IDB_NOT_ACCESSIBLE  = 0x08
} idbAccess_t;

/******************************************************************************
* idbRange_t - IDB+ simple range checking structure
*
* For example, "{1,3}" implies a range from 1 to 3 inclusive, while 
* "{0,0}" implies no range checking.
*/
typedef struct
{
    ulong_t     min_range;  /* lower bondary value of a range */
    ulong_t     max_range;  /* upper bondary value of a range */
} idbRange_t;

/******************************************************************************
* idbType_t - ASN.1 MIB object type enumerations
*/
typedef enum
{
    IDB_NULL = 0,
    IDB_INTEGER,
    IDB_OCTET_STRING,
    IDB_OBJECT_IDENTIFIER,
    IDB_IpAddress,
    IDB_MACAddress,
    IDB_Counter,
    IDB_Guage,
    IDB_TimeTicks,
    IDB_Opaque,
    IDB_Port_List,
    IDB_BridgeId,
    IDB_Counter64,
    IDB_RowStatus
} idbType_t;

/* 
 * Additional common MIB object types that have the same storage requirements
 * as one of the idbType_t enum object types.  These are mapped to one of the
 * appropriate enum values.
 */
#define IDB_NetworkAddress      IDB_IpAddress
#define IDB_Guage32             IDB_Guage
#define IDB_Counter32           IDB_Counter
#define IDB_BITS                IDB_OCTET_STRING
#define IDB_Unsigned32          IDB_Guage
#define IDB_MacAddress          IDB_MACAddress
#define IDB_Integer32           IDB_INTEGER
#define IDB_DisplayString       IDB_OCTET_STRING

 
/******************************************************************************
* idb_t - internal IDB+ request/response data structure
*
* DESCRIPTION
* This typedef structure is filled in by idbDispatch() and is primarily used
* by the IDB+ object handler routines (i.e., (*pObjHandler)()).
*
* Note that the indexObjCount (in idbOidTable_t) is the number of objects
* (i.e., the number of SNMP indices) that make up the IDB+ index.  The
* indexSubIdCount is the number of sub-identifiers (stored as ulong_t's) that
* make up the index(es).  For example, the "rfc1213:ipRoutEntry" table entry
* has one index and this index is of type 'IpAddress', which has 4
* sub-identifiers. Thus, for this index, the indexSubIdCount value could have
* a value between [0-4] and indexSubIdCountMax would be 4.  A SNMP Get or Set
* request requires all 4 sub-identifiers, while a Get-Next requires fewer
* sub-identifiers.
*
* For this example:
*     idbOidTable_t.indexObjCount = 1,
*     idb_t.indexSubIdCount       = [0-4]
*     idb_t.indexSubIdCountMax    = 4
*/
typedef struct idb_s
{
    ulong_t   * pIndex;             /* pointer to the index storage array */
    ulong_t     indexSubIdCount;    /* number of sub-identifiers in index */
    ulong_t     indexSubIdCountMax; /* max number of index sub-identifiers */
    void      * pValueBuf;          /* pointer to the value data buffer */
    ulong_t     valueLen;           /* byte length of the pValueBuf space */
    ushort_t    localId;            /* local ID enum value (gen'ed w/IDBGEN) */
    ushort_t    flags;              /* row operation (Set/Get/Get-Next) flags */
} idb_t;

/******************************************************************************
* idbObjDesc_t - describes the IDB+ MIB object 
*
* DESCRIPTION
* This typedef structure holds the IDB+ object descriptor. IDBGEN creates a
* LOCAL (i.e., static) table of this typedef in the IDB+ Module source file.
*/
#define IDB_VALID       0x01    /* this object is valid */
#define IDB_DURABLE     0x02    /* this object is durable (saved in NVM) */
#define IDB_STORAGE     0x04    /* IDB controls the storage -- not used */
#define IDB_HIDDEN      0x08    /* this object is hidden from SNMP */
#define IDB_INDEX       0x10    /* this object is an index */
#define IDB_IMPLIED     0x20    /* this object is a SNMP IMPLIED string/OID */
#define IDB_ISDISPLAY   0x40    /* string is really a DisplayString object */
typedef struct
{
    ushort_t      localId;      /* local ID enum value (gen'ed w/IDBGEN) */
    ushort_t      lastOidPrefixSubId;   /* last OID prefix sub-identifier */
    ulong_t       size;         /* byte size of object data value */
    idbRange_t    range;        /* simple range checking values */
    idbType_t     type;         /* object type (e.g., IDB_INTEGER) */
    idbAccess_t   access;       /* object access permission (e.g., IDB_READ) */
    ulong_t       flags;        /* flags (e.g., IDB_HIDDEN, IDB_VALID) */
    STATUS        (*pObjHandler)( idbRequest_t request, idb_t * pIdb ); 
                                /* pointer to object handler function */
    char *        pAltObjName;  /* alternate object name tag string (or null)*/
    char *        pObjName;     /* object name string (in object tag format) */
} idbObjDesc_t;

/******************************************************************************
* idbOidTable_t - OID/indexing information structure for scalar/table objects
*
* DESCRIPTION
* This typedef structure holds the SNMP OID information for SNMP table and
* scalar objects.  IDBGEN creates a LOCAL table of this typedef in the IDB+
* Module source file.
*/
typedef enum {                   /* structure type for idbOidTable_t */
    IDB_TERMINATOR = 0,          /* structure terminator */
    IDB_SNMP_STRUCT,             /* SNMP type structure */
    IDB_LDAP_STRUCT,             /* LDAP type structure -- future extension */
    IDB_LAST_STRUCT              /* indicates number of structure types */
} idbStruct_t;
    
#define IDB_NUM_INDICES 6        /* max allowed number of indices per table */
#define MAX_SUBID_INDEX_COUNT 64 /* max allowed sub-IDs for all indices */
#define MAX_SUBID_COUNT 128      /* max # of sub-identifers for SNMP */
#define OID_PREFIX_SIZE 32       /* max # of sub-identifers for OID prefix */

/* TODO: To save space use a OID string pointer for the OID list. */
typedef struct
{
    idbStruct_t   structType;           /* management structure type */
    ulong_t       oidPrefixWoLastSubId[OID_PREFIX_SIZE];
                                        /* OID prefix w/o last sub-identifier*/
    ulong_t       oidPrefixLen;         /* # sub-identifers in OID prefix */
    ulong_t       indexObjCount;        /* number of objects in index */
    ulong_t       indexSubIdCountMax;   /* max # of sub-identifiers in index */
    const char *  pIndexName[IDB_NUM_INDICES];
                                        /* ptr to index object tag name(s)*/
    const idbObjDesc_t * pObjDesc;      /* ptr to object descriptor array */
} idbOidTable_t;

/******************************************************************************
* idbXlateTable_t - translation table structure
*
* DESCRIPTION
* This typedef structure is used to link the OID table entries and the object
* descriptors.  There is an array of idbXlateTable_t structures indexed by
* localId for each registered IDB+ Module.  IDBGEN creates a LOCAL table of
* this typedef in the IDB+ Module source file.
*/
typedef struct
{
    idbOidTable_t   * pOidTable;    /* pointer to idbOidTable_t entry */
    idbObjDesc_t    * pObjDesc;     /* pointer to idbObjDesc_t entry */
} idbXlateTable_t;

/*****************************************************************************
* objEntry_t - Module Hash Table / Object Hash Table structure definition
*
* DESCRIPTION
* This typedef structure is used to point to entries in the Module Hash Table
* and the Object Hash Table.  The Module Hash table is used to get the
* pointer to the base object Translate Table entry for this IDB+ Module.  The
* Object Hash Table is used to find the pointer to the desired object's
* Translate Table entry (i.e., idbXlateTable_t).
*
* The pKey for Module Hash Table is the ASCII IDB+ Module name string (e.g.,
* "rfc1213").  The pKey for the Object Hash Table is the ASCII IDB+ Object Tag
* string (e.g., "rfc1213:sysDescr").
*/
typedef struct 
{
    char *            pKey;         /* pointer to module/object tag string */
    idbXlateTable_t * pXlateTable;  /* pointer to translate table entry */
} objEntry_t;

/******************************************************************************
* IDB+ Info Get definitions, bit fields to retrieve information.
* There is a 1-to-1 mapping between these enum's and idbInfoGet_t.
*/
typedef enum
{
    IDB_LOCALID                 = 0x0001,
    IDB_LASTOIDPREFIXSUBID      = 0x0002,
    IDB_SIZE                    = 0x0004,
    IDB_RANGE                   = 0x0008,
    IDB_TYPE                    = 0x0010,
    IDB_OIDPREFIXWOLASTSUBID    = 0x0020,
    IDB_OIDPREFIXLEN            = 0x0040,
    IDB_INDEXOBJCOUNT           = 0x0080,
    IDB_INDEXSUBIDCOUNTMAX      = 0x0100,
    IDB_PINDEXNAME              = 0x0200,
    IDB_ALL_VALUES              = -1
} idbEleAccess_t;

/******************************************************************************
* idbInfoGet_t - get indexing information for tables
*/
typedef struct
{
    ulong_t      localId;               /* Local ID value */
    ulong_t      lastOidPrefixSubId;    /* last OID prefix sub-identifier */
    ulong_t      size;                  /* Default size of object */
    idbRange_t   range;                 /* simple range checking values */
    idbType_t    type;                  /* object type (e.g., IDB_INTEGER) */
    ulong_t      oidPrefixWoLastSubId[OID_PREFIX_SIZE];
                                        /* OID prefix w/o last sub-identifier*/
    ulong_t      oidPrefixLen;          /* # of sub-identifers in OID prefix */
    ulong_t      indexObjCount;         /* number of objects in index */
    ulong_t      indexSubIdCount;       /* number of index sub-identifiers */
    ulong_t      indexSubIdCountMax;    /* max # of sub-identifiers in index */
    const char * pIndexName[IDB_NUM_INDICES]; /* ptr to index object name(s) */
} idbInfoGet_t;

/******************************************************************************
* idbParam_t - object parameter structure for the IDB+ row-operation
*
* DESCRIPTION
* This typedef structure is used to hold information for one of the
* individual objects for a row-operation (e.g., row-set).  The idbRowAlloc()
* routine allocates a link list array of idbParams_t structures for the
* row-operation.  There is one idbParams_t array element for each object in
* the row-operation. The pParams in the idbRow_t structure points to the
* first element in this array.
*/

typedef struct idbParams_s {
    struct idbParams_s * pNext;     /* pointer to the next object struct */
    char        * pObjName;         /* pointer to IDB+ object tag string */
    ulong_t     * pIndex;           /* pointer to the index storage array */
    ulong_t       indexSubIdCount;  /* number of index sub-identifiers */
    void        * pValueBuf;        /* pointer to the value data buffer */
    ulong_t       valueLen;         /* byte length of the pValueBuf space */
    ushort_t      flags;            /* row-operation (Set/Get/Get-Next) flags*/
    ushort_t      reserved;         /* used to long word align struct */
    ulong_t       errorValue;       /* individual object SNMP_ERROR code */
} idbParams_t;

#define IDB_ERROR_FLAG          0x8000  /* indicates SNMP_ERROR for this */
                                        /* row-set/get item */
                                        /* idbParams_t.errorValue contains */
                                        /* this SNMP_ERROR */
#define IDB_VALIDATED_FLAG      0x0001  /* indicates set object validated */
#define IDB_COMMITED_FLAG       0x0002  /* indicates set object commited */
#define IDB_RETRIEVED_FLAG      0x0004  /* indicates get object was retrieved*/
#define IDB_NOSUCHINSTANCE_FLAG 0x0008  /* SNMPv2 noSuchInstance exception */
#define IDB_FIRST_FLAG          0x0010  /* first object in a row-operation */
#define IDB_LAST_FLAG           0x0020  /* last object in a row-operation */
#define IDB_RECURSIVE_FLAG      0x0040  /* this request is recursive */
#define IDB_REMOVE_FLAG         0x0080  /* remove table columnar instance(s) */
#define IDB_NVM_GET_FLAG        0x0100  /* remove table columnar instance(s) */
#define IDB_FORCE_SET_FLAG      0x0200  /* indicates force set is called */

#define IDB_ROW_ALLOC_NUM       85  /* number of idbRow_t to pre-allocate */
#define IDB_ROWPARAM_ALLOC_NUM  255 /* number of idbParams_t to pre-allocate */

/******************************************************************************
* idbRow_t - IDB+ row-operation control structure
*
* DESCRIPTION
* This typedef structure is used to control a single row-operation (e.g.,
* row-set).  The idbRowAlloc() routine allocates a idbRow_t structure plus
* the associated idbParams_t structures.
*
* Note that the pNext pointer is not currently used.
*/

typedef struct idbRow_s {
    struct idbRow_s * pNext;        /* pointer to the next object struct */
    ulong_t           numObjects;   /* number of objects for row operation */
    idbParams_t     * pParams;      /* pointer to object parameters struct */
} idbRow_t;


/******************************************************************************
* If INCLUDE_IDB_STATS_SHOW is defined, the following structure of IDB+
* statistics is maintained by the IDB+ Engine.  These statistics can be
* displayed using idbStatsShow().
*/
typedef struct {
    ulong_t     idbInitCalled;

    ulong_t     objAllocEntry;
    ulong_t     objAddFailed;
    ulong_t     objTotalCount;
    ulong_t     objTableFull;
    ulong_t     objAlreadyExists;
    ulong_t     objNeedsAdding;

    ulong_t     modAllocEntry;
    ulong_t     modAddFailed;
    ulong_t     modTotalCount;
    ulong_t     modTableFull;
    ulong_t     modAlreadyExists;
    ulong_t     modRegisterCalled;

    ulong_t     modDeRegisterCalled;
    ulong_t     modDeRegisterFound;

    ulong_t     idbSnmpOidInitCalled;
    ulong_t     idbSnmpRegisterCalled;

    ulong_t     snmpObjVisible;
    ulong_t     snmpObjInvisible;
    ulong_t     snmpObjRegFailed;

    ulong_t     idbDispatchCalled;
    ulong_t     idbDispatchBufNull;
    ulong_t     idbDispatchRangeErr;
    ulong_t     idbDispatchUnknown;
    ulong_t     idbDispatchSet;
    ulong_t     idbForceSet;
    ulong_t     idbDispatchReadOnly;
    ulong_t     idbDispatchGet;
    ulong_t     idbDispatchGetNext;
    ulong_t     idbDispatchSetNvm;
    ulong_t     idbDispatchValidate;
    ulong_t     idbDispatchCommit;
    ulong_t     idbDispatchUnknownRequest;
    ulong_t     idbDispatchAltObject;
    ulong_t     idbDispatchEntryHook;
    ulong_t     idbDispatchExitHook;
    ulong_t     idbDispatchObjHandler;
    ulong_t     idbDispatchNullHandler;

    ulong_t     idbGetCalled;
    ulong_t     idbNvmGetCalled;
    ulong_t     idbSetCalled;
    ulong_t     idbValidateCalled;
    ulong_t     idbCommitCalled;
    ulong_t     idbGetNextCalled;
    ulong_t     idbSetNvmCalled;
    ulong_t     idbRemoveCalled;
    ulong_t     idbGetInfoCalled;
    ulong_t     idbObjectShowCalled;
    ulong_t     idbAltObjectSetCalled;
    ulong_t     idbAltObjectListCalled;
    ulong_t     idbAltObjectHideCalled;
    ulong_t     idbAltObjectHideListCalled;
    ulong_t     idbObjectNameNextGetCalled;

    ulong_t     idbIndexesAreEqual;
    ulong_t     idbNextSimpleIndex;
    ulong_t     idbNextAddressIndex;
    ulong_t     idbScalarValidate;
    ulong_t     idbNextScalarIndex;

    ulong_t     idbIndexRange;
    ulong_t     idbInvalidRange;
    ulong_t     idbInvalidLength;
    ulong_t     idbTooBig;
    ulong_t     idbNullBuffer;
    ulong_t     idbAltObjectError;
    ulong_t     idbGenError;
    ulong_t     idbObjectHidden;
    ulong_t     idbNoError;

    ulong_t     idbNoNextInstance;
    ulong_t     idbNoSuchInstance;
    ulong_t     idbNoSuchObject;
    ulong_t     idbNoCreation;
    ulong_t     idbInconsistValue;
    ulong_t     idbInconsistName;
    ulong_t     idbResourceUnavail;
    ulong_t     idbCommitFailed;
    ulong_t     idbUndoFailed;
    ulong_t     idbAuthorizationError;
    ulong_t     idbNotWritable;
    ulong_t     idbNoAccess;
    ulong_t     idbWrongType;
    ulong_t     idbWrongValue;
    ulong_t     idbWrongLength;
    ulong_t     idbEndOfMibView;
    ulong_t     idbWrongEncoding;
} idbStats_t;

#ifdef INCLUDE_IDB_STATS_SHOW
#define IDBSTATS(stat)     idbStats.stat++
#else
#define IDBSTATS(stat)
#endif

/******************************************************************************
* FUNCTION PROTOTYPES.
*/

/******************************************************************************
 * idbInit - initialize the IDB+ Engine
 */
IMPORT STATUS idbInit ( ulong_t nObjects,
                        ulong_t nModules );

/******************************************************************************
* idbDispatch - main IDB+ Engine dispatching interface function
*/
IMPORT STATUS idbDispatch ( idbRequest_t    request,
                            char *          pObjName,
                            ulong_t *       pIndex,
                            ulong_t *       pIndexSubIdCount,
                            void *          pValueBuf,
                            ulong_t *       pValLen,
                            ushort_t *      pFlags );

/******************************************************************************
* idbModuleSearch - search IDB+ Engine for the given IDB+ Module name
*/
STATUS idbModuleSearch ( char * pModuleName );

/******************************************************************************
* idbModuleRegister - registers an IDB+ Module
*/
IMPORT STATUS idbModuleRegister ( char * pModuleName,
                                  idbXlateTable_t * pXlateTable );

/******************************************************************************
* idbModuleDeRegister - De-registers an IDB+ Module 
*/
IMPORT  STATUS idbModuleDeRegister ( char * pModuleName );

/******************************************************************************
* Standard IDB+ Helper Routines
*/
IMPORT STATUS idbGet ( char *       pObjName,
                       ulong_t *    pIndex,
                       ulong_t      indexSubIdCount,
                       void *       pValueBuf,
                       ulong_t *    pValLen);

IMPORT STATUS idbNvmGet ( char *       pObjName,
                          ulong_t *    pIndex,
                          ulong_t      indexSubIdCount,
                          void *       pValueBuf,
                          ulong_t *    pValLen);

IMPORT STATUS idbSet ( char *       pObjName,
                       ulong_t *    pIndex,
                       ulong_t      indexSubIdCount,
                       void *       pValueBuf,
                       ulong_t      valLen);

IMPORT STATUS idbForceSet ( char *       pObjName,
                            ulong_t *    pIndex,
                            ulong_t      indexSubIdCount,
                            void *       pValueBuf,
                            ulong_t      valLen);

IMPORT STATUS idbValidate ( char *      pObjName,
                            ulong_t *   pIndex,
                            ulong_t     indexSubIdCount,
                            void *      pValueBuf,
                            ulong_t     valLen);

IMPORT STATUS idbCommit ( char *        pObjName,
                          ulong_t *     pIndex,
                          ulong_t       indexSubIdCount,
                          void *        pValueBuf,
                          ulong_t       valLen);

IMPORT STATUS idbGetNext ( char *       pObjName,
                           ulong_t *    pIndex,
                           ulong_t *    pIndexSubIdCount,
                           void *       pValueBuf,
                           ulong_t *    pValLen);

IMPORT STATUS idbNvmSet ( char *        pObjName,
                          ulong_t *     pIndex,
                          ulong_t       indexSubIdCount,
                          void *        pValueBuf,
                          ulong_t       valLen);

IMPORT STATUS idbRemove ( char *       pObjName,
                          ulong_t *    pIndex,
                          ulong_t      indexSubIdCount);

/******************************************************************************
* Row-Operation IDB+ Helper Routines
*/
STATUS idbRowAlloc( ulong_t numObjects, idbRow_t ** ppRow );
STATUS idbRowFree( idbRow_t * pRow );
STATUS idbRowItemAdd( idbRow_t *    pRow,
                      ulong_t       groupIndex,
                      char *        pObjName,
                      ulong_t *     pIndex,
                      ulong_t       indexSubIdCount,
                      void *        pValueBuf,
                      ulong_t       valueLen);
STATUS idbRowSet( idbRow_t * pGroupCookie );
STATUS idbRowGet( idbRow_t * pGroupCookie );
STATUS idbRowValidate( idbRow_t * pGroupCookie );
STATUS idbRowCommit( idbRow_t * pGroupCookie );
STATUS idbRowGetNext( idbRow_t * pGroupCookie );
STATUS idbRowExamine( idbRow_t *    pRow,
                      ulong_t       groupIndex,
                      ulong_t *     pFlags,
                      ulong_t *     pErrorValue);

/******************************************************************************
* IDB+ Show/Utility Routines
*/
IMPORT STATUS idbObjInfoGet ( char         * pObjName,
                              ulong_t        valMask,
                              idbInfoGet_t * pIdbInfo);

IMPORT STATUS idbObjectShow ( char      * pObjName,
                              ulong_t   * pIndex,
                              ulong_t     indexSubIdCount);

IMPORT STATUS idbModuleShow ( char * pModuleId );
IMPORT STATUS idbObjectShowAll ( char * pObjName, ulong_t indexSubIdCount);
IMPORT STATUS idbModuleList ( void );
IMPORT STATUS idbStructureShow ( idb_t * pIdb );
IMPORT STATUS idbHashShow( void );
IMPORT STATUS idbStatsShow( void );
IMPORT STATUS idbObjNameGet ( ulong_t   * pOidPrefix,
                              ulong_t     oidPrefixLen,
                              ulong_t   * pOidMatchLen,
                              ulong_t   * pIndexSubIdCount,
                              idbType_t * pObjType,
                              uchar_t   * pObjName );
IMPORT STATUS idbObjectNameNextGet( char * pObjName, char ** ppObjNameNext );


/******************************************************************************
* idbDispatch() Hook Registration Routines
*/
IMPORT STATUS idbParseObjectHookAdd ( FUNCPTR pParseObjHook );
IMPORT STATUS idbUnknownObjectHookAdd ( FUNCPTR pUnkObjHook );
IMPORT STATUS idbDispatchEntryHookAdd ( FUNCPTR pEntryHook );
IMPORT STATUS idbDispatchExitHookAdd ( FUNCPTR pExitHook );

/******************************************************************************
* Wrapper Functions for SNMP_ERROR Reporting and Handling
*/
/* Miscellaneous IDB+ errors */
IMPORT STATUS  idbErrorIndexRange( void );
IMPORT STATUS  idbErrorInvalidRange( void );
IMPORT STATUS  idbErrorInvalidLength( void );
IMPORT STATUS  idbErrorNullBuffer( void );
IMPORT STATUS  idbErrorAltObject( void );
IMPORT STATUS  idbErrorObjectHidden( void );
IMPORT STATUS  idbErrorNoNextInstance( void );
IMPORT STATUS  idbErrorRequestMap( idbRequest_t request );

/* SNMPv1 specific errors */
/* not used internally in NEOS 2.0 */               /*  2 - noSuchName */
/* not used internally in NEOS 2.0 */               /*  3 - badValue */
/* not used internally in NEOS 2.0 */               /*  4 - readOnly */

/* SNMPv2/v3 errors */
IMPORT STATUS  idbNoError( void );                 /*  0 - noError */
IMPORT STATUS  idbErrorTooBig( void );             /*  1 - errorTooBig */
IMPORT STATUS  idbErrorGenError( void );           /*  5 - genError */
IMPORT STATUS  idbErrorNoAccess( void );           /*  6 - noAccess */
IMPORT STATUS  idbErrorWrongType( void );          /*  7 - wrongType */
IMPORT STATUS  idbErrorWrongLength( void );        /*  8 - wrongLength */
IMPORT STATUS  idbErrorWrongEncoding( void );      /*  9 - wrongEncoding */
IMPORT STATUS  idbErrorWrongValue( void );         /* 10 - wrongValue */
IMPORT STATUS  idbErrorNoCreation( void );         /* 11 - noCreation */
IMPORT STATUS  idbErrorInconsistValue( void );     /* 12 - inconsistValue */
IMPORT STATUS  idbErrorResourceUnavail( void );    /* 13 - resourceUnavailable*/
IMPORT STATUS  idbErrorCommitFailed( void );       /* 14 - commitFailed */
IMPORT STATUS  idbErrorUndoFailed( void );         /* 15 - undoFailed */
IMPORT STATUS  idbErrorAuthorizationError( void ); /* 16 - authorizationError */
IMPORT STATUS  idbErrorNotWritable( void );        /* 17 - notWritable */
IMPORT STATUS  idbErrorInconsistName( void );      /* 18 - inconsistName */

/* SNMPv2/v3 exceptions */
IMPORT STATUS  idbErrorNoSuchObject( void );       /* 0 - noSuchObject */
IMPORT STATUS  idbErrorNoSuchInstance( void );     /* 1 - noSuchInstance */
IMPORT STATUS  idbErrorEndOfMibView( void );       /* 2 - endOfMibView */

/******************************************************************************
* Utility Functions for Index Manipulation
*/
IMPORT STATUS idbIndexesAreEqual ( ulong_t *   pIndex1,
                                    ulong_t *   pIndex2,
                                    ulong_t     indexLength );

IMPORT STATUS  idbNextScalarIndex( idb_t * );
IMPORT STATUS  idbNextSimpleIndex( idb_t * );
IMPORT STATUS  idbScalarValidate( idbRequest_t request, idb_t * );
IMPORT STATUS  idbNextAddressIndex( idb_t * );
IMPORT STATUS  idbScalarIntGet( char * pObjName, ulong_t * pRetVal );

/******************************************************************************
* Get/Set Utility Routines
*/
IMPORT void ulongSet ( idb_t * pIdb, ulong_t value );
IMPORT ulong_t ulongGet ( idb_t * pIdb );
IMPORT void ucharSet ( idb_t * pIdb, uchar_t value );
IMPORT uchar_t ucharGet ( idb_t * pIdb );
IMPORT void octetSet ( idb_t * pIdb, uchar_t * pValue, ulong_t length );
IMPORT uchar_t * octetGet ( idb_t * pIdb );
IMPORT void ushortSet ( idb_t * pIdb, long value );
IMPORT ushort_t ushortGet ( idb_t * pIdb );
IMPORT void quadSet ( idb_t * pIdb, unsigned long  value );
IMPORT unsigned long  quadGet ( idb_t * pIdb );
IMPORT void pUlongSet ( idb_t * pIdb, ulong_t * pValue );
IMPORT ulong_t * pUlongGet ( idb_t * pIdb );
IMPORT void pUcharSet ( idb_t * pIdb, uchar_t *pValue );
IMPORT uchar_t * pUcharGet ( idb_t * pIdb );
IMPORT void oidSet ( idb_t * pIdb, ulong_t * pVal, ulong_t length );
IMPORT ulong_t * oidGet ( idb_t * pIdb );
IMPORT void slongSet ( idb_t * pIdb, long value );
IMPORT long slongGet ( idb_t * pIdb );

/********************************************************************************
 * IDB+ supported method routines for MIB API implementation
 */
int idb2mApiReqTypeGet ( idbRequest_t request );
STATUS mApiException2IdbErrorGet ( int mApiException );
STATUS mApi2IdbErrorGet( ushort_t mApiError );

/* conversion routines used by IDB and RowStatus library */
IMPORT STATUS rs2idbErrorGet ( void * pObjInfo, int rsErrorState );
IMPORT idbRequest_t rs2idbReqTypeGet ( int rsRequest );
IMPORT STATUS idb2rsReqTypeGet ( idbRequest_t request );

IMPORT STATUS SNMP_Initialize( void );

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __INCidbLibh */
